package com.test.security.springsecuritydemo7.filter;

import java.io.IOException;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created with IntelliJ IDEA.
 * Description:
 *
 * @author lzy
 * @since 2023/1/3 下午4:47
 */
public class AuthenticationLoggingFilter implements Filter {
    private static final Logger LOGGER = LoggerFactory.getLogger(AuthenticationLoggingFilter.class);

    /**
     * @param servletRequest
     * @param servletResponse
     * @param filterChain
     * @throws IOException
     * @throws ServletException
     */
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        var request = (HttpServletRequest) servletRequest;
        final String requestId = request.getHeader("Request-Id");
        LOGGER.info("Successfully authenticated request with id " + requestId);
        filterChain.doFilter(servletRequest, servletResponse);
    }
}
